const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}
function setPromise(data){
  let BaseUrl = 'https://whale-cloud.vercel.app'
  return new Promise((resolve,reject)=>{
    wx.request({
      url: BaseUrl+data.url,
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: data.method,
      data: data.data,
      success(res) {
        if (res.data && res.data.code === 200) {
          resolve(res.data)
        }
      },
      fail(error) {
        reject(error)
      }
    })
  })
}
module.exports = {
  formatTime,
  setPromise
}
